<template>
	<view class="container">
		<view class="box">
			<view class="li">
				<text>昵称</text>
				<view>
					<input type="text" v-model="user.username" />
				</view>
			</view>
			<view class="li">
				<text>积分</text>
				<view>
					{{user.jifen_num}}
				</view>
			</view>
		</view>

		<button @click="sub">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					username: '',
					jifen_num: ''
				}
			}
		},
		onShow() {
			this.get_info()
		},
		methods: {
			get_info() {
				this.user = uni.getStorageSync('user')
				console.log(this.user._wxopenid)
				uniCloud.callFunction({
					name: 'getUser',
					data: {
						_wxopenid: this.user._wxopenid
					}
				}).then(res => {
					this.user = res.result.data[0]
					console.log(res)
					uni.setStorageSync('user', this.user)
				})
				console.log(this.user)
			},
			sub() {
				uni.showLoading({
					title:'修改中~'
				})
				uniCloud.callFunction({
					name: 'setUser',
					data: {
						...this.user
					}
				}).then(res => {
					uni.hideLoading()
					uni.showToast({
						title:'修改成功~'
					})
					console.log(res)
				})
			}
		}
	}
</script>

<style scoped>
	.container {
		height: calc(100vh - 100rpx);
		display: flex;
		background: #f5f5f5;
		flex-direction: column;
		justify-content: space-between;
	}

	.box {
		padding: 20rpx;
		box-sizing: border-box;

	}

	.box .li {
		display: flex;
		align-items: center;
		padding: 10px 0;
		border-bottom: 1px solid #bebebe;
		margin-top: 10rpx;
	}

	.box .li>text {
		display: block;
		width: 100rpx;
		text-align: center;
		font-size: 30rpx;
	}

	.box .li view {
		flex: 1;
	}

	.box .li view input {
		width: 100%;
		height: 80rpx;
		border-radius: 10rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
		border: 1px solid #ccc;
	}

	button {
		width: 80%;
		height: 70rpx;
		line-height: 70rpx;
		font-size: 34rpx;
		background: #006594;
		color: #fff;
	}
</style>